"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var AuthenticateUser_1 = require('../models/AuthenticateUser');
var BaseService_1 = require('./BaseService');
var UsersDao_1 = require('../dao/UsersDao');
var TokensDao_1 = require('../dao/TokensDao');
var UsersService = (function (_super) {
    __extends(UsersService, _super);
    function UsersService() {
        _super.call(this);
        this.usersDao = new UsersDao_1.UsersDao();
        this.tokensDao = new TokensDao_1.TokensDao();
    }
    UsersService.prototype.login = function (username, password, callback) {
        var _this = this;
        this.usersDao.get(username, password, function (err1, user) {
            if (!err1 && user) {
                _this.tokensDao.add(user._id, function (err2, token) {
                    var authUser = new AuthenticateUser_1.AuthenticateUser();
                    authUser.user = user;
                    authUser.token = token;
                    callback(err2, authUser);
                });
            }
            else {
                callback(err1);
            }
        });
    };
    UsersService.prototype.register = function (user, callback) {
        this.usersDao.add(user, callback);
    };
    UsersService.prototype.update = function (user, callback) {
        this.usersDao.update(user, callback);
    };
    return UsersService;
}(BaseService_1.BaseService));
exports.UsersService = UsersService;
